package template;

import java.util.Arrays;

public class SixteenTransfer {
    public static void main(String[] args) {
        int solve = solve("012345BZ16");
        System.out.println(solve);

        String rotate = rotate(new int[]{1, 2, 3, 4, 5, 6}, 2);
        System.out.println(rotate);


    }
    public static int solve (String s) {//找出字符串中的最大16进制数，以十进制输出
        // write code here
        int begin = 0;
        int end = 0;
        int result = 0;
        for(int i = 0; end < s.length(); i++) {
            if ( (Character.isDigit(s.charAt(i))) || (s.charAt(i) >= 'A' && s.charAt(i) <= 'F') ) {
                end++;
                result = Math.max(Integer.parseInt(s.substring(begin, end),16), result);
            } else {
                begin = i+1;
                end = begin;
            }
        }
        return result;
    }
    public static String rotate(int[] nums, int k) {//将数组向右循环移动k个单位
//        String sb= Arrays.toString(nums);
        //左闭右开
        k%=nums.length;
        StringBuilder sb=new StringBuilder();
        for(int i=0;i<nums.length;i++){
            sb.append(nums[i]);
        }
        int n=sb.length();
        return sb.substring(n-k,n)+sb.substring(0,n-k);

    }

}
